<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Student/index')}">学生列表</a></li>
        <li class="active"><a href="#">学生详情</a></li>
    </ul>
    <div class="col-lg-10 col-md-12 margin-top-20">
        <div class="">
                    <div class="row">
                        <table class="table table-bordered" >
                            <tr>
                                <th style="width:10%">学员姓名</th>
                                <td style="width:90%">{$tname}</td>
                            </tr>
                            <tr>
                                <th>班级情况</th>
                                <td>
                                    <table class="table table-bordered">
                                        <tr>
                                            <th class="col-xs-2">课程</th>
                                            <th class="col-xs-2">班级</th>
                                            <th class="col-xs-1">状态</th>
                                            <th class="col-xs-1">入班时间</th>
                                            <th class="col-xs-1">课时情况</th>
                                            <th class="col-xs-1">总费用(元)</th>
                                            <th class="col-xs-1">实付金额(元)</th>
                                            <th class="col-xs-1">发票</th>
                                            <th class="col-xs-3">操作</th>
                                        </tr>
                                        <notempty name="data">
                                            <foreach name="data" item="vo">
                                                <tr>
                                                    <td>{$vo.course_name}</td>
                                                    <td>{$vo.cname}</td>
                                                    <td>{$vo.class_status}</td>
                                                    <td>{:date('Y-m-d',$vo.insert_class_time)}</td>
                                                    <td>{$vo.progress}/{$vo.course_hour}</td>
                                                    <td>{$vo.ctotal_price|default=0.00}</td>
                                                    <td>{$vo.pay_amount|default=0.00}</td>
                                                    <if condition="$vo.bill_status eq 2">
                                                        <td>已开</td>
                                                        <elseif condition="$vo.bill_status eq 1"/>
                                                        <td>未开</td>
                                                        <else/>
                                                        <td>不需要</td>
                                                    </if>
                                                    <td>
                                                        <a href="javascript:;" class="stu_visit_ctrl">查看回访记录</a>
                                                        <a ><span class="glyphicon glyphicon-chevron-down"></span></a> |
                                                        <if condition="$vo.order_status eq 1">
                                                            <if condition="$vo.is_refuse==1">
                                                                <a href="javascript:;" attr_id="{$vo.cid}">退课中</a>
                                                                <elseif condition="$vo.is_refuse==2">
                                                                    <a href="javascript:;"  attr_id="{$vo.cid}">已退课</a>
                                                                </elseif>
                                                                <elseif condition="$vo.is_refuse==3">
                                                                    <a href="javascript:;" attr_id="{$vo.cid}">
                                                                        拒绝退课
                                                                        <if condition="isset($vo.csstatus) && $vo.csstatus eq 0">
                                                                            <a href="javascript:;" class="stu_change_class" attr_id="{$vo.cid}">转班</a>
                                                                            <else/>
                                                                            <a  href="{:url('classes/classes/edit',array('id'=>$vo.cid))}">选座</a>
                                                                        </if>
                                                                    </a>
                                                                </elseif>
                                                                <else/>
                                                                <a href="javascript:;" class="refund_msg" attr_total="{$vo.total_num}" attr_signupused="{$vo.signup_used}" attr_progress="{$vo.used_lesson}" attr_signup="{$vo.signup_price}"
                                                                   attr_bill="{$vo.bill_status}" attr_order="{$vo.order_id}"  attr_id="{$vo.cid}" attr_school_id="{$vo.school_id}" attr_course_id="{$vo.coid}">
                                                                    退课
                                                                </a> |
                                                                <if condition="isset($vo.csstatus) && $vo.csstatus eq 0">
                                                                    <a href="javascript:;" class="stu_change_class" attr_id="{$vo.cid}">转班</a>
                                                                    <else/>
                                                                    <a  href="{:url('classes/classes/edit',array('id'=>$vo.cid))}">选座</a>
                                                                </if>
                                                            </if>
                                                            <elseif condition="$vo.order_status eq 4"/>
                                                            <a href="javascript:;" attr_id="{$vo.cid}">已退课</a>
                                                        </if>
                                                    </td>
                                                </tr>
                                                <tr class="stu_visit_show">
                                                    <td colspan="8" style="padding:8px 0px;">
                                                        <if condition="$vo.visit==false">
                                                            本学生在此班级暂无回访内容
                                                            <else/>
                                                            <table class="table table-bordered">
                                                                <tr>
                                                                    <th class="col-xs-2">回访标题</th>
                                                                    <th class="col-xs-2">回访老师</th>
                                                                    <th class="col-xs-6">回访内容</th>
                                                                    <th class="col-xs-2">回访日期</th>
                                                                </tr>
                                                                <foreach name="$vo.visit" item="x">
                                                                    <tr>
                                                                        <td>{$x.title}</td>
                                                                        <td>{$x.teacher_id}</td>
                                                                        <td>{$x.content}</td>
                                                                        <td>{:date('Y-m-d',$x.create_time)}</td>
                                                                    </tr>
                                                                </foreach>
                                                                </tr>
                                                            </table>
                                                        </if>
                                                    </td>
                                                </tr>
                                            </foreach>
                                        </notempty>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <th>请假情况</th>
                                <td>
                                    <table class="table table-bordered">
                                        <tr>
                                            <th class="col-xs-2">课程</th>
                                            <th class="col-xs-4">所在班级</th>
                                            <th class="col-xs-2">日期</th>
                                            <th class="col-xs-4">调课去的班级</th>
                                        </tr>
                                        <foreach name="student_leave" item="vo">
                                            <tr>
                                                <td>{$vo.course_name}</td>
                                                <td>{$vo.cname}</td>
                                                <td>{:date('Y-m-d',$vo.create_time)}</td>
                                                <td>{$vo.adjustcname|default="本次请假未调课"}</td>
                                            </tr>
                                        </foreach>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <th>学生动态 </th>
                                <td>
                                    <table class="table table-bordered">
                                        <tr>
                                            <th class="col-xs-8">学生动态</th>
                                            <th class="col-xs-4">日期</th>
                                        </tr>
                                        <foreach name="studen_active" item="vo">
                                            <tr>
                                                <td>{$vo.content}</td>
                                                <td>{:date('Y-m-d',$vo.create_time)}</td>
                                            </tr>
                                        </foreach>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>
        </div>
    </div>
</div>

<div id="refund_msg">
    <form action="{:url('Student/refund')}  " class="well  row js-ajax-form" method="post" style="margin:0;">
        <input type="hidden" name="class_id" class="class_id_view" value="">
        <input type="hidden" name="student_id" value="{$id}">
        <input type="hidden" name="school_id" value="">
        <input type="hidden" name="course_id" value="">
        <input type="hidden" name="order_id" value="">
        <input type="hidden" name="refund_money" value="" disabled>

        <label class="col-xs-12 form-group"  style="margin-bottom:15px;">
                退费方式:<span class="form-required">*</span>
                <select class="form-control" name="way" id="">
                    <option value="1">微信</option>
                    <option value="2">支付宝</option>
                    <option value="3">现金</option>
                    <option value="4">银行卡</option>
                    <option value="5">代金券</option>
                </select>
        </label>
        <label class="form-group col-xs-12" style="margin-bottom:15px;">
            退课原因:<span class="form-required">*</span>
            <textarea class="form-control" name="content"  rows="3" placeholder="请输入退课原因" required="required"></textarea>
        </label>
        <label class="form-group col-xs-12" style="margin-bottom:15px;">
            发票税费(元):
            <input class="form-control" type="number" min="0" name="tax" id="tax_number" placeholder="若无发票可不填" value="">
        </label>
        <label class="form-group col-xs-12" style="margin-bottom:15px;">
            扣除优惠金额(元):
            <input class="form-control" type="number" min="0" name="discount" id="discount" value="" placeholder="请输入优惠的金额">
        </label>
        <label class="form-group col-xs-12" style="margin-bottom:15px;">
            退费金额(元):<span class="form-required">*</span>
            <input class="form-control" type="number" name="refuse_price" id="result_money" value="" placeholder="请输入退课的金额" required="required">
        </label>
         <button class="btn btn-danger btn-sm 6 js-ajax-submit"  style='display:none' id="refund_submit"  type="submit"></button>
    </form>
</div>

<div id="stu_change_class" style="display: none;">
    <form action="{:url('Student/change_class')}" class="form-horizontal js-ajax-form margin-top-20" method="post" style="margin:30px;">
        <label class="form-group">
            校区:
            <select class="form-control" name="school_id" id="school_id" style="width:179px;">
                <option value='0'>全部</option>
                <notempty name="schools">
                    <volist name="schools" id="vo">
                        <if condition="isset($param.school_id) && $param.school_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.name}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>
        <br>
        <label class="form-group">
            课程:
            <select class="form-control" name="course_id" id="course_id" style="width:179px;">
                <option value='0'>请先选择校区</option>
                <notempty name="course_name">
                    <volist name="courses" id="vo">
                        <if condition="isset($param.course_id) && $param.course_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.course_name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.course_name}</option>
                        </if>
                    </volist>
                </notempty>
                </select>
        </label>
        <br>

        <label class="form-group">
            班级:
            <select class="form-control" name="class_id" id="class_id" style="width:179px;">
                <option value='0'>请先选择课程</option>
                <notempty name="classes">
                    <volist name="classes" id="vo">
                        <if condition="isset($param.class_id) && $param.class_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.name}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>
        <br>

        <label class="form-group">
            费用:
            <input type="number" class="form-control" id="cost" name="cost" value="0" readonly>
        </label>
        <input type="hidden" name="old_change_old_ids" value="" id="old_change_old_ids">
        <input type="hidden" name="student_id"  id="old_change_student_id" value="{$id}">
        <button type="submit"  id="stu_change_submit" class='js-ajax-submit' style="display:none"></button>
    </form>
</div>


<script type="text/javascript" src="__STATIC__/js/admin.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('input[name="birthday"]').datepicker();//日期

    });

    $('body').on('click','.stu_visit_ctrl',function () {
        $(this).parent().parent().next().toggle(150);
        if($(this).text() == "查看回访记录" ){
            $(this).text('收起回访记录');
            $(this).next('a').children('span')
                .addClass('glyphicon-chevron-up')
                .removeClass('glyphicon-chevron-down');
        }else {
            $(this).text("查看回访记录");
            $(this).next('a').children('span')
                .addClass('glyphicon-chevron-down')
                .removeClass('glyphicon-chevron-up');
        }
    });

    $('body').on('click','.refund_msg',function () {
        $(".class_id_view").val($(this).attr('attr_id'));
        $('input[name="school_id"]').val($(this).attr('attr_school_id'));
        $('input[name="course_id"]').val($(this).attr('attr_course_id'));
        $('input[name="order_id"]').val($(this).attr('attr_order'));

        //总课时数(包含连报)
        var total_lesson = $(this).attr('attr_total');
        //最初报名时已上课时数
        var signup_used = $(this).attr('attr_signupused');
        //现在已上过的课时数
        var used_lesson = $(this).attr('attr_progress');
        //报名费
        var signup_price = $(this).attr('attr_signup');
        //发票
        var bill_status = $(this).attr('attr_bill');
        if(bill_status == 0){
            //不需要
            $('#tax_number').attr("readonly","readonly");
        }

        $parent=$(this).parent().parent('tr');
        //课时
        $now_lesson=$parent.find('td').eq(4).html();
        //实付金额
        $total_price=$parent.find('td').eq(6).html();

        //$string=$now_lesson.split("/");
        //$total_lesson=$string[1];
        //$used_lesson=$string[0];

        //课时数
        var lesson_num = parseInt(total_lesson) - parseInt(signup_used);
        //每节课价格
        $one_price = ((parseFloat($total_price)- parseFloat(signup_price)) / parseInt(lesson_num) ).toFixed(2);

        //总退费金额
        $zong = 0;
        if(used_lesson==0){
            $total_price = parseFloat($total_price) - parseFloat(signup_price);
            $zong = parseFloat($total_price).toFixed(2);
        }else{
            //报班后又上过的课时数
            var left = parseInt(used_lesson) - parseInt(signup_used);

            $zong = $one_price * (lesson_num - left);
            $zong = $zong.toFixed(2);
        }
        $('input[name="refuse_price"]').val($zong);
        $('input[name="refund_money"]').val($zong);

        layer.open({
            type: 1,
            btn: ['提交'],
            title: '退课相关信息',
            area: ['400px', '500px'],
            content: $('#refund_msg'),
            yes: function (index, layero) {
                 
                $('#refund_submit').click();

            }
        })
    });

    //退费费用
    $('body').on('change','#discount',function () {
        var discount = $(this).val();
        var total = $('input[name="refund_money"]').val();

        if(discount <= 0 || !discount){
            $('#result_money').val(total);
            return false;
        }else{
            total = parseFloat(total) - parseFloat(discount);
            total = total.toFixed(2);
            $('#result_money').val(total);
        }
    });

    //计算最终退费金额
    $('body').on('change','#tax_number',function () {
        //初始退费额
        var init_money = $('input[name="refund_money"]').val();
        //发票税费
        var tax = $(this).val();
        if(!tax || typeof(tax)==undefined || isNaN(tax)){
            $('#result_money').val(parseFloat(init_money).toFixed(2));
        }else{
            if(parseFloat(init_money) > parseFloat(tax)){
                //减去税费
                init_money = parseFloat(init_money) - parseFloat(tax);
            }
            $('#result_money').val(parseFloat(init_money).toFixed(2));
        }
    });

    $('body').on('click','.stu_change_class',function () {
        orginal_cid=$(this).attr('attr_id');

        layer.open({
            type: 1,
            btn: ['提交'],
            area: ['400px', '400px'],
            title: '请选择要转去的班级',
            content: $('#stu_change_class'),
            yes: function (index, layero) {
                $('#stu_change_submit').click();

            }
        })
    });

    $('#course_id').on('change',function () {
        var sid = $(this).val();
        var cid = $('#school_id').val();
        if(sid == 0){
            $('#class_id').empty();
            var html = '<option value=\"0\">请选择</option>';
            $('#class_id').html(html);
            return false;
        }
        $.ajax({
            url:"{:url('student/ajax_course_class')}",
            type:'post',
            dataType:'json',
            data:{"course_id":sid,'school_id':cid},
            success:function(jsonData){
                $('#class_id').empty();
                var html = '<option value=\"0\">请选择</option>';

                if(jsonData.code == 1){
                    for(var i in jsonData.data){
                        html += '<option value=\"'+jsonData.data[i].id+'\">'+jsonData.data[i].name+'</option>';
                    }
                }
                $('#class_id').html(html);
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });
    });
    $('#school_id').on('change',function () {
        var sid = $(this).val();
        if(sid == 0){
            $('#course_id').empty();
            var html = '<option value=\"0\">请选择</option>';
            $('#course_id').html(html);
            return false;
        }
        $.ajax({
            url:"{:url('student/ajax_class')}",
            type:'post',
            dataType:'json',
            data:{"school_id":sid},
            success:function(jsonData){
                console.log(jsonData.data);
                $('#course_id').empty();
                var html = '<option value=\"0\">请选择</option>';

                if(jsonData.code == 1){
                    for(var i in jsonData.data){
                        html += '<option value=\"'+jsonData.data[i].id+'\">'+jsonData.data[i].course_name+'</option>';
                    }
                }
                $('#course_id').html(html);
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });
    });


    $('#class_id').on('change',function () {
        var cid = $(this).val();
        $("#old_change_old_ids").val(orginal_cid);

        if(cid == 0){
            $('#cost').val('0');
        }
        $.ajax({
            url:"{:url('student/calculateCost')}",
            type:'post',
            dataType:'json',
            data:{
                "class_id":cid,
                "orginal_cid":orginal_cid
            },
            success:function(data){
                data=jQuery.parseJSON(data);
                $("#cost").val((data.cost));

            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });

    });



</script>

</body>
